<?php
class People{
    public $head;
    public $body;

    //不太此类中直接给属性赋值
    function __construct(){

    }
}

//定义具备建造者所需实现的方法
abstract class PeopleBuilder{
    abstract function buildHead();
    abstract function buildBody();
}

//具体建造类实现具体业务
class ChildBuilder extends PeopleBuilder{
    private $people;
    function __construct(){
        $this->people = new people;
    }

    function buildHead(){
        echo "this is a child's head!";
    }
    function buildBody(){
        echo "this is a child's body!";
    }
    function returnResult(){
        return $this->people;
    }
}

class AdultBuilder extends PeopleBuilder{
    private $people;
    function __construct(){
        $this->people = new people;
    }

    function buildHead(){
        echo "this is a adult's head!";
    }
    function buildBody(){
        echo "this is a adult's body!";
    }
    function returnResult(){
        return $this->people;
    }
}

//指挥者，指挥者负责与调用客户端交互，决定创建什么样的产品
class Director{
    function __construct(Peoplebuilder $builder){
        $builder->buildHead();
        $builder->buildBody();
    }
}


//测试
$builder = new AdultBuilder();
$director = new Director($builder);
$person = $builder->returnResult();
//this is a adult's head! this is a adult's body!
